/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bluetooth;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import components.CtrlPcCanvas;

import midlet.ClientApp;

/**
 *
 * @author wssccc
 * @improved cccssw
 */
public abstract class BlueCanvasBase extends Canvas implements CommandListener {

    protected BlueComm bs = null;
    private Command cmdExit = null;
    private Command cmdBack = null;

    public void setBlueComm(BlueComm bluecomm){
        this.bs = bluecomm;
    }
    
    public BlueCanvasBase() {
        //添加退出按钮
        cmdExit = new Command("Exit", Command.SCREEN, 1);
        this.addCommand(cmdExit);
        //添加返回按钮
        cmdBack = new Command("Back", Command.BACK, 1);
        this.addCommand(cmdBack);

        this.setCommandListener(this);
    }
    private void ExitMIDlet(){
        ClientApp.exitMidlet();
    }
    public void commandAction(Command cmd, Displayable dis) {
        if (cmd == cmdExit) {
            try {
                bs.disconnect();
            } finally {
                ExitMIDlet();
            }


        }else if(cmd==cmdBack){
             try {
                bs.disconnect();
            } finally {
                BlueCanvasBuilder bcc=new BlueCanvasBuilder(new CtrlPcCanvas(),ClientApp.instance);
                new Thread(bcc).start();
            }
        }
    }
}
